<?php

class IndexController extends Zend_Controller_Action {
	
	public function init() {
		/* Initialize action controller here */
	}
	
	public function indexAction() {
		$email = new Zend_Form_Element_Text ( 'email' );
		$email->setLabel ( 'Email address' )->addFilter ( 'StringToLower' )->setRequired ( true )->addValidator ( 'NotEmpty', true )->addValidator ( 'EmailAddress' );
		
		$submit = new Zend_Form_Element_Submit ( 'submit' );
		$submit->setLabel ( 'Contact us' );
		
		$form = new Zend_Form ();
		
		$form->setMethod ( 'post' );
		
		$form->addElements ( array ($email, $submit ) );
		
		if ($this->_request->isPost ()) {
			$formData = $this->_request->getPost ();
			if ($form->isValid ( $formData )) {
				echo 'success';
				exit ();
			} else {
				$form->populate ( $formData );
			}
		}
		$this->view->form = $form;
	}
	
	public function signAction() {
		$request = $this->getRequest ();
		$form = new Application_Form_Guestbook ();
		if ($this->getRequest ()->isPost ()) {
			if ($form->isValid ( $request->getPost () )) {
				$comment = new Application_Model_Guestbook ( $form->getValues () );
				$mapper = new Application_Model_GuestbookMapper ();
				$mapper->save ( $comment );
				return $this->_helper->redirector ( 'index' );
			}
		}
		$this->view->form = $form;
	}
	
	
}

